# -*- coding: utf-8 -*-
import scrapy
from scrayp_test1.items.HousingItem import HousingItem
import win_unicode_console
win_unicode_console.enable()
from db import dao


class Housing(scrapy.Spider):
    #设置name
    name = "Housing"
    #设定域名
    allowed_domains = ["171.221.172.13:8888"]
    #填写爬取地址
    start_urls = ["http://171.221.172.13:8888/lottery/accept/projectList?projectNoList="]
    #编写爬取方法
    def parse(self, response):
        #实例一个容器保存爬取的信息
        item = HousingItem()
        #这部分是爬取部分，使用xpath的方式选择信息，具体方法根据网页结构而定
        #先获取每个课程的div
        # for box in response.xpath('//div[@class="course-card-container"]/a[@target="_self"]'):
        for box in response.xpath('//table//tbody//tr'):
            project = box.xpath('.//td/text()').extract()
            # dao.insert_housing(project[2], project[0], project[1])
            dao.insert_housing2(project[2], project[0], project[1])
            #返回信息
            # yield item
